package v1

import (
	"math"
	"pq/service"
	"pq/stat"
	"strconv"
)

type StatController struct{
	TokenCheckController
}

var us = service.NewUserService()
var cs = service.CategoryService{}

func (sc *StatController) GetUserStat() {
	//var maps []orm.Params
	uid,_ := strconv.Atoi(sc.Uid)
	cate := us.GetCategory(uid)
	res := map[string]interface{}{}
	all := stat.Stat_user_question_count(sc.Uid,cate.Lft,cate.Rgt)
	right := stat.Stat_user_right_answer_count(sc.Uid,cate.Lft,cate.Rgt)
	res["test_count"] = all //做过的题目
	res["right_rate"] = 0.0
	if right <= 0 {
		res["right_rate"] = 0
	}else {
		res["right_rate"] =  float64(int((float64(right)/float64(all)) * 100))
	}
	rank := int64(math.Ceil(5 * float64(right) + 1.2 * float64(all))) % 10000
	if rank <= 0 {
		rank = 10000
	}
	res["rank"]	= rank
	sc.Single(res)
}